//
//  SSGetCouponDoneView.swift
//  拾舍清洁
//
//  Created by sky.wei on 2023/3/8.
//

import UIKit

public typealias GetCouponResult = ()->()
class SSGetCouponDoneView: UIView {
    
    var getCouponResult: GetCouponResult?     // 闭包
    
    @IBOutlet weak var containterView: UIView!
    @IBOutlet weak var bgView: UIView!
    
    class func couponDoneView()->SSGetCouponDoneView{
        let view = Bundle.main.loadNibNamed("SSGetCouponDoneView", owner: nil, options: nil)?.last as! SSGetCouponDoneView
        view.frame = CGRect(x: 0, y: 0, width: ScreenWidth, height: ScreenHeight)
        keyWindow?.addSubview(view)
//        dissmissToEscaping {
//            keyWindow?.addSubview(view)
//        }
        return view
    }

    @IBOutlet weak var lookCouponBtn: UIButton!
    
    override func awakeFromNib() {
        super.awakeFromNib()
        
        bgView.backgroundColor = UIColor.black.withAlphaComponent(0.3)
        lookCouponBtn.layer.masksToBounds = true
        lookCouponBtn.layer.cornerRadius = 8
        containterView.layer.masksToBounds = true
        containterView.layer.cornerRadius = 8
    }
    
    func numberResult(_ finished: @escaping GetCouponResult) {
        getCouponResult = finished
    }
    
    @IBAction func lookCouponAction(_ sender: Any) {
        removeFromSuperview()
        getCouponResult!()
    }
    
    @IBAction func closeAction(_ sender: Any) {
        removeFromSuperview()
    }
}
let keyWindow : UIWindow? = {
//    if #available(iOS 13.0, *) {
//        return UIApplication.shared.connectedScenes.filter { $0.activationState == .foregroundActive
//    }.compactMap { $0 as? UIWindowScene }.first?.windows.filter { $0.isKeyWindow }.first;
//    }else {
//        return UIApplication.shared.keyWindow!
//    }
    return UIApplication.shared.keyWindow!
}()

//let keyWindow = UIApplication.shared.connectedScenes
//        .filter({$0.activationState == .foregroundActive})
//        .map({$0 as? UIWindowScene})
//        .compactMap({$0})
//        .first?.windows
//        .filter({$0.isKeyWindow}).first
